package com.haixee.parkdemo.gateway.security;

import com.haixee.parkdemo.common.entity.AuthData;
import org.springframework.security.authentication.AbstractUserDetailsReactiveAuthenticationManager;
import org.springframework.security.authentication.AccountExpiredException;
import org.springframework.security.authentication.ReactiveAuthenticationManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import javax.security.auth.login.AccountNotFoundException;

@Component
public class TokenAuthenticationManager extends AbstractUserDetailsReactiveAuthenticationManager {
    @Override
    public Mono<Authentication> authenticate(Authentication authentication) {

        AuthData authData = (AuthData) authentication.getPrincipal();
        if (authData == null || !authData.getAuth()) {
            return Mono.error(new AccountNotFoundException());
        }

        return Mono.just(authentication);
    }

    @Override
    protected Mono<UserDetails> retrieveUser(String username) {
        return null;
    }
}
